﻿using System;
using System.Linq;
using System.Collections.Generic;
using DAL;
using Entity;
using Utils;
using Library;
using DataContext;


namespace PaymentBLL
{
    public class CtrAccount
    {
        public int ClearAccount()
        {
            int r = DB.PaymentInstance.uspClearAccount();
            if (r > 0)
                return DB.HighLowGameInstance.uspClearAccount();
            return 0;
        }

        public int LoginAccount(string userName, string password,string iP,int deviceTypeId, int clientTypeId)
        {
            return DB.PaymentInstance.uspAccountLogin(userName, password, iP, deviceTypeId, clientTypeId);
        }

        public int AddAccountAuAgIn(int accountId, string accountName, int accountTypeId,
            int paymentGatewayId, string paymentGatewayName, string paymentGatewayUnit,
            string paymentAccountInfo, string systemAccountInfo, 
            int amount, int vndIn, int auAdd, int agAdd, int status, int resultCode, string description)
        {
            return DB.PaymentInstance.uspAccountAuAgIn(accountId, accountName, accountTypeId, 
                paymentGatewayId, paymentGatewayName, paymentGatewayUnit, paymentAccountInfo, systemAccountInfo,
                amount, vndIn, auAdd, agAdd, status, resultCode, description);
        }

        public int AddAccountAuAgItemIn(int accountId,string accountName,int accountTypeId, 
            int paymentGatewayId,string paymentGatewayName,string paymentGatewayUnit, 
            string paymentAccountInfo,string systemAccountInfo,int itemInId,string itemInName, int status, int resultCode,
            int totalAmountIn,int totalVndIn,int quantity,int totalAuAdd,int totalAgAdd,string description)
        {
            return DB.PaymentInstance.uspAccountAuAgItemIn(accountId, accountName, accountTypeId, 
                paymentGatewayId, paymentGatewayName, paymentGatewayUnit, 
                paymentAccountInfo, systemAccountInfo, itemInId, itemInName, 
                totalAmountIn, totalVndIn, quantity, totalAuAdd, totalAgAdd,status,resultCode, description);
        }

        public int AddAuAgAccount(int accountId, int consumerId, int auAdd, int agAdd, string description)
        {
            return DB.PaymentInstance.uspAccountPlayAddAuAg(accountId, consumerId, auAdd, agAdd, description);
        }

        public int SubAuAgAccount(int accountId, int consumerId, int auSub, int agSub, string description)
        {
            return DB.PaymentInstance.uspAccountPlaySubAuAg(accountId, consumerId, auSub, agSub, description);
        }

        public int InsertAccount(string name,string pass,int typeId,string fullName,string email,int status, ref int? id)
        {
            return DB.PaymentInstance.uspAccountInsert(name, pass, typeId, fullName, email, status, string.Empty, ref id);
        }

        public List<uspAccountSelectByResult> SelectAccountBy(int id, int typeId, string name, int status, int currentPage, int pageSize, ref int? totalRecord)
        {
            return DB.PaymentInstance.uspAccountSelectBy(id, typeId, name, status, currentPage, pageSize, ref totalRecord).ToList();
        }

        public int UpdateAccountStatus(int id, int status)
        {
            return DB.PaymentInstance.uspAccountUpdateStatus(id, status);
        }

        public List<uspAccountAssetsStatisticsResult> SelectAssetsStatistics(int id, string name,
            ref long? totalVndIn, ref long? totalReceiveAu, ref long? totalReceiveAg,
            ref long? totalAuOut, ref long? totalAgOut, ref long? totalVndOut,
            ref long? totalAuPlay, ref long? totalAgPlay, ref long? totalAuBonus, ref long? totalAgBonus,
            ref long? totalAgToAu, ref long? totalAuFromAg,
            ref int? currentAu, ref int? currentAg, int currentPage, int pageSize, ref int? totalRecord)
        {
            return DB.PaymentInstance.uspAccountAssetsStatistics(id, name, ref totalVndIn,
                ref totalReceiveAu, ref totalReceiveAg,
                ref totalAuOut, ref totalAgOut, ref totalVndOut,
                ref totalAuPlay, ref totalAgPlay, ref totalAuBonus, ref totalAgBonus,
                ref totalAgToAu, ref totalAuFromAg,
                ref currentAu, ref currentAg, currentPage, pageSize, ref totalRecord).ToList();
        }

        public uspAccountInfoSelectByNameResult SelectAccountInfoByName(string accountName)
        {
            return DB.PaymentInstance.uspAccountInfoSelectByName(accountName).FirstOrDefault();
        }

        public uspAccountInfoSelectResult SelectAccountInfo(int accountId)
        {
            return DB.PaymentInstance.uspAccountInfoSelect(accountId).FirstOrDefault();
        }
    }
}
